﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using AnycleLiu.Common.Collection;

namespace AnycleLiu.Common.Tests
{
    [TestFixture]
    public class TestBinaryOrderTree
    {
        private IList<int> list = new List<int>();

        [SetUp]
        public void InitData()
        {
            int Min = 0;
            int Max =20000;
            Random randNum = new Random();
            for (int i = 0; i <10000; i++)
            {
               list.Add( randNum.Next(Min, Max));
            }
        }
        [TearDown]
        public void ClearData()
        {
            list.Clear();
        }
        //[Test]
        public void TestListOrder()
        {
            DateTime start = DateTime.Now;
           // Array.Sort<int>(list.ToArray<int>());
            foreach (var v in list) Console.Write(v + "  ");
            Console.WriteLine(DateTime.Now - start);
        }
        [Test]
        public void TestPreorderTraversal()
        {
            DateTime start = DateTime.Now;
            ITree<int> tree = new BinarySortTree<int>();
            tree.Build(list);
           // tree.PreorderTraversal();
            Console.WriteLine("-------------------------");
            IList<TreeNode<int>> nodes = tree.Find(list[2]);
            Console.WriteLine(list[2]);
            Console.WriteLine(nodes.Count);
            foreach (var v in nodes) Console.Write(v.Data + "      ");
            Console.WriteLine("-------------------------");
            Console.WriteLine(DateTime.Now - start);
        }
    }
}
